// UsbPhone.h : Declaration of the CUsbPhone

#ifndef __USBPHONE_H_
#define __USBPHONE_H_

#include "resource.h"       // main symbols
#include <atlctl.h>


/////////////////////////////////////////////////////////////////////////////
// CUsbPhone
class ATL_NO_VTABLE CUsbPhone : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public IDispatchImpl<IUsbPhone, &IID_IUsbPhone, &LIBID_UPHONECTRLLib>,
	public CComControl<CUsbPhone>,
	public IPersistStreamInitImpl<CUsbPhone>,
	public IOleControlImpl<CUsbPhone>,
	public IOleObjectImpl<CUsbPhone>,
	public IOleInPlaceActiveObjectImpl<CUsbPhone>,
	public IViewObjectExImpl<CUsbPhone>,
	public IOleInPlaceObjectWindowlessImpl<CUsbPhone>,
	public IConnectionPointContainerImpl<CUsbPhone>,
	public IPersistStorageImpl<CUsbPhone>,
	public ISpecifyPropertyPagesImpl<CUsbPhone>,
	public IQuickActivateImpl<CUsbPhone>,
	public IDataObjectImpl<CUsbPhone>,
	public IProvideClassInfo2Impl<&CLSID_UsbPhone, &DIID__IUsbPhoneEvents, &LIBID_UPHONECTRLLib>,
	public IPropertyNotifySinkCP<CUsbPhone>,
	public CComCoClass<CUsbPhone, &CLSID_UsbPhone>
{
public:
	CUsbPhone()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_USBPHONE)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CUsbPhone)
	COM_INTERFACE_ENTRY(IUsbPhone)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IViewObjectEx)
	COM_INTERFACE_ENTRY(IViewObject2)
	COM_INTERFACE_ENTRY(IViewObject)
	COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY(IOleInPlaceObject)
	COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
	COM_INTERFACE_ENTRY(IOleControl)
	COM_INTERFACE_ENTRY(IOleObject)
	COM_INTERFACE_ENTRY(IPersistStreamInit)
	COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
	COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
	COM_INTERFACE_ENTRY(IQuickActivate)
	COM_INTERFACE_ENTRY(IPersistStorage)
	COM_INTERFACE_ENTRY(IDataObject)
	COM_INTERFACE_ENTRY(IProvideClassInfo)
	COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()

BEGIN_PROP_MAP(CUsbPhone)
	PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
	PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
	// Example entries
	// PROP_ENTRY("Property Description", dispid, clsid)
	// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(CUsbPhone)
	CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(CUsbPhone)
	CHAIN_MSG_MAP(CComControl<CUsbPhone>)
	DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);



// IViewObjectEx
	DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IUsbPhone
public:
	STDMETHOD(DeInitPhone)();
	STDMETHOD(RF_Function)(short OffTimeInMs);
	STDMETHOD(MutePhoneRing)(INT isMute);
	STDMETHOD(DecodeEvent)(INT EventId, BSTR * strEvent, int strBuffLen);
	STDMETHOD(HandFreeOff)();
	STDMETHOD(HandFreeOn)();
	STDMETHOD(QueryPhoneStatus)();
	STDMETHOD(HandFreeAndDial)(BSTR strDialNumber);
	STDMETHOD(DialNumber)(BSTR strDialNumber);
	STDMETHOD(get_SW_Version)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_HW_Version)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_PhoneHWVersion)(/*[out, retval]*/ INT *pVal);
	STDMETHOD(ReleasePhone)();
	STDMETHOD(get_PhoneStatus)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_PhoneType)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(InitPhone)(void);

	HRESULT OnDraw(ATL_DRAWINFO& di)
	{
		RECT& rc = *(RECT*)di.prcBounds;
		Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);

		SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
		LPCTSTR pszText = _T("ATL 3.0 : UsbPhone");
		TextOut(di.hdcDraw, 
			(rc.left + rc.right) / 2, 
			(rc.top + rc.bottom) / 2, 
			pszText, 
			lstrlen(pszText));

		return S_OK;
	}
};

#endif //__USBPHONE_H_
